
import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.event.HyperlinkEvent;

/**
 * @program MHAG
 * @ mhagGUI, partially generated by NetBeans IDE
 * @version 1.0
 * @author Tifa@mh3
 */

public class MhagGui extends javax.swing.JFrame {

    /** Creates new form MhagGui */
    public MhagGui() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
        private void initComponents() {

                rankGroup = new javax.swing.ButtonGroup();
                hunterTypeGroup = new javax.swing.ButtonGroup();
                sexGroup = new javax.swing.ButtonGroup();
                outputGroup = new javax.swing.ButtonGroup();
                buttonGroup1 = new javax.swing.ButtonGroup();
                jTabbedPane1 = new javax.swing.JTabbedPane();
                calculator = new javax.swing.JPanel();
                rank = new javax.swing.JPanel();
                lowRank = new javax.swing.JRadioButton();
                highRank = new javax.swing.JRadioButton();
                hunterType = new javax.swing.JPanel();
                blade = new javax.swing.JRadioButton();
                gunner = new javax.swing.JRadioButton();
                sex = new javax.swing.JPanel();
                male = new javax.swing.JRadioButton();
                female = new javax.swing.JRadioButton();
                setup = new javax.swing.JPanel();
                weaponMenu = new javax.swing.JComboBox();
                headMenu = new javax.swing.JComboBox();
                chestMenu = new javax.swing.JComboBox();
                armsMenu = new javax.swing.JComboBox();
                waistMenu = new javax.swing.JComboBox();
                legsMenu = new javax.swing.JComboBox();
                charmMenu = new javax.swing.JComboBox();
                weaponLabel = new javax.swing.JLabel();
                headLabel = new javax.swing.JLabel();
                chestLabel = new javax.swing.JLabel();
                armsLabel = new javax.swing.JLabel();
                waistLabel = new javax.swing.JLabel();
                legsLabel = new javax.swing.JLabel();
                charmLabel = new javax.swing.JLabel();
                charmSkillLabel = new javax.swing.JLabel();
                weaponSlot1 = new javax.swing.JComboBox();
                weaponSlot2 = new javax.swing.JComboBox();
                weaponSlot3 = new javax.swing.JComboBox();
                headSlot1 = new javax.swing.JComboBox();
                headSlot2 = new javax.swing.JComboBox();
                headSlot3 = new javax.swing.JComboBox();
                chestSlot1 = new javax.swing.JComboBox();
                chestSlot2 = new javax.swing.JComboBox();
                chestSlot3 = new javax.swing.JComboBox();
                armSlot1 = new javax.swing.JComboBox();
                armSlot2 = new javax.swing.JComboBox();
                armSlot3 = new javax.swing.JComboBox();
                waistSlot1 = new javax.swing.JComboBox();
                waistSlot2 = new javax.swing.JComboBox();
                waistSlot3 = new javax.swing.JComboBox();
                legSlot1 = new javax.swing.JComboBox();
                legSlot2 = new javax.swing.JComboBox();
                legSlot3 = new javax.swing.JComboBox();
                charmSlot1 = new javax.swing.JComboBox();
                charmSlot2 = new javax.swing.JComboBox();
                charmSlot3 = new javax.swing.JComboBox();
                charmSkill1 = new javax.swing.JComboBox();
                charmSkill2 = new javax.swing.JComboBox();
                skillPoint1 = new javax.swing.JLabel();
                skillPoint2 = new javax.swing.JLabel();
                output = new javax.swing.JPanel();
                text = new javax.swing.JRadioButton();
                html = new javax.swing.JRadioButton();
                code = new javax.swing.JRadioButton();
                saveOutput = new javax.swing.JButton();
                jTextData = new javax.swing.JTextField();
                jLabel1 = new javax.swing.JLabel();
                jScrollPreview = new javax.swing.JScrollPane();
                jTextPreview = new javax.swing.JTextArea();
                setNamePanel = new javax.swing.JPanel();
                jTextSetName = new javax.swing.JTextField();
                viewer = new javax.swing.JPanel();
                jScrollPreview2 = new javax.swing.JScrollPane();
                jTextPreview2 = new javax.swing.JTextArea();
                codeBook = new javax.swing.JPanel();
                codeBookName = new javax.swing.JTextField();
                codeBookLoad = new javax.swing.JButton();
                codeBookSave = new javax.swing.JButton();
                convert = new javax.swing.JPanel();
                convertTEXT = new javax.swing.JRadioButton();
                convertHTML = new javax.swing.JRadioButton();
                Output = new javax.swing.JButton();
                jScrollPane1 = new javax.swing.JScrollPane();
                codeList = new javax.swing.JList();
                loadSetInteract = new javax.swing.JButton();
                getSetInteract = new javax.swing.JButton();
                deleteInteract = new javax.swing.JButton();
                undoInteract = new javax.swing.JButton();
                generator = new javax.swing.JPanel();
                about = new javax.swing.JPanel();
                jScrollAbout = new javax.swing.JScrollPane();
                jEditorAbout = new javax.swing.JEditorPane();
                jLabel2 = new javax.swing.JLabel();
                jPanel1 = new javax.swing.JPanel();
                jScrollHelpList = new javax.swing.JScrollPane();
                helpList = new javax.swing.JList();
                jScrollHelpText = new javax.swing.JScrollPane();
                helpText = new javax.swing.JTextArea();

                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
                setTitle("MHAG: Monster Hunter Armor Generator   Ver 1.0");
                setResizable(false);
                addWindowListener(new java.awt.event.WindowAdapter() {
                        public void windowClosing(java.awt.event.WindowEvent evt) {
                                formWindowClosing(evt);
                        }
                });

                jTabbedPane1.setFont(new java.awt.Font("Monospaced", 1, 14)); // NOI18N
                jTabbedPane1.setOpaque(true);

                rank.setBorder(javax.swing.BorderFactory.createTitledBorder("Rank"));
                rank.setToolTipText("Change rank type, reset set");

                rankGroup.add(lowRank);
                lowRank.setFont(new java.awt.Font("Monospaced", 0, 12));
                lowRank.setText("Low Rank");
                lowRank.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                lowRankActionPerformed(evt);
                        }
                });

                rankGroup.add(highRank);
                highRank.setFont(new java.awt.Font("Monospaced", 0, 12));
                highRank.setSelected(true);
                highRank.setText("High Rank");
                highRank.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                highRankActionPerformed(evt);
                        }
                });

                org.jdesktop.layout.GroupLayout rankLayout = new org.jdesktop.layout.GroupLayout(rank);
                rank.setLayout(rankLayout);
                rankLayout.setHorizontalGroup(
                        rankLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(rankLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(rankLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(lowRank)
                                        .add(highRank))
                                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                );
                rankLayout.setVerticalGroup(
                        rankLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(rankLayout.createSequentialGroup()
                                .add(lowRank)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(highRank))
                );

                hunterType.setBorder(javax.swing.BorderFactory.createTitledBorder("Hunter Type"));
                hunterType.setToolTipText("Change hunter type, reset set");

                hunterTypeGroup.add(blade);
                blade.setFont(new java.awt.Font("Monospaced", 0, 12));
                blade.setSelected(true);
                blade.setText("Blademaster");
                blade.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                bladeActionPerformed(evt);
                        }
                });

                hunterTypeGroup.add(gunner);
                gunner.setFont(new java.awt.Font("Monospaced", 0, 12));
                gunner.setText("Gunner");
                gunner.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                gunnerActionPerformed(evt);
                        }
                });

                org.jdesktop.layout.GroupLayout hunterTypeLayout = new org.jdesktop.layout.GroupLayout(hunterType);
                hunterType.setLayout(hunterTypeLayout);
                hunterTypeLayout.setHorizontalGroup(
                        hunterTypeLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(hunterTypeLayout.createSequentialGroup()
                                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(blade))
                        .add(hunterTypeLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(gunner)
                                .addContainerGap(35, Short.MAX_VALUE))
                );
                hunterTypeLayout.setVerticalGroup(
                        hunterTypeLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(hunterTypeLayout.createSequentialGroup()
                                .add(blade)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(gunner))
                );

                sex.setBorder(javax.swing.BorderFactory.createTitledBorder("Gender"));
                sex.setToolTipText("Switch armor names");

                sexGroup.add(male);
                male.setFont(new java.awt.Font("Monospaced", 0, 12));
                male.setSelected(true);
                male.setText("Male");
                male.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                maleActionPerformed(evt);
                        }
                });

                sexGroup.add(female);
                female.setFont(new java.awt.Font("Monospaced", 0, 12));
                female.setText("Female");
                female.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                femaleActionPerformed(evt);
                        }
                });

                org.jdesktop.layout.GroupLayout sexLayout = new org.jdesktop.layout.GroupLayout(sex);
                sex.setLayout(sexLayout);
                sexLayout.setHorizontalGroup(
                        sexLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(sexLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(sexLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(male)
                                        .add(female))
                                .addContainerGap(30, Short.MAX_VALUE))
                );
                sexLayout.setVerticalGroup(
                        sexLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(sexLayout.createSequentialGroup()
                                .add(male)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(female))
                );

                setup.setBorder(javax.swing.BorderFactory.createTitledBorder("Setup"));
                setup.setPreferredSize(new java.awt.Dimension(625, 390));

                weaponMenu.setFont(new java.awt.Font("Monospaced", 0, 12));
                weaponMenu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No Slot", "1 Slot", "2 Slots", "3 Slots" }));
                weaponMenu.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                weaponMenuActionPerformed(evt);
                        }
                });

                headMenu.setFont(new java.awt.Font("Monospaced", 0, 12));
                headMenu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                headMenu.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                headMenuActionPerformed(evt);
                        }
                });

                chestMenu.setFont(new java.awt.Font("Monospaced", 0, 12));
                chestMenu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                chestMenu.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                chestMenuActionPerformed(evt);
                        }
                });

                armsMenu.setFont(new java.awt.Font("Monospaced", 0, 12));
                armsMenu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                armsMenu.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                armsMenuActionPerformed(evt);
                        }
                });

                waistMenu.setFont(new java.awt.Font("Monospaced", 0, 12));
                waistMenu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                waistMenu.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                waistMenuActionPerformed(evt);
                        }
                });

                legsMenu.setFont(new java.awt.Font("Monospaced", 0, 12));
                legsMenu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                legsMenu.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                legsMenuActionPerformed(evt);
                        }
                });

                charmMenu.setFont(new java.awt.Font("Monospaced", 0, 12));
                charmMenu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                charmMenu.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                charmMenuActionPerformed(evt);
                        }
                });

                weaponLabel.setFont(new java.awt.Font("Lucida Sans Typewriter", 0, 12));
                weaponLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/weapon.png"))); // NOI18N
                weaponLabel.setLabelFor(weaponMenu);
                weaponLabel.setToolTipText("Weapon");

                headLabel.setFont(new java.awt.Font("Lucida Sans Typewriter", 0, 12));
                headLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/head.png"))); // NOI18N
                headLabel.setLabelFor(headMenu);
                headLabel.setToolTipText("Head");

                chestLabel.setFont(new java.awt.Font("Lucida Sans Typewriter", 0, 12));
                chestLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/chest.png"))); // NOI18N
                chestLabel.setLabelFor(chestMenu);
                chestLabel.setToolTipText("Chest");

                armsLabel.setFont(new java.awt.Font("Lucida Sans Typewriter", 0, 12));
                armsLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/arms.png"))); // NOI18N
                armsLabel.setLabelFor(armsMenu);
                armsLabel.setToolTipText("Arms");

                waistLabel.setFont(new java.awt.Font("Lucida Sans Typewriter", 0, 12));
                waistLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/waist.png"))); // NOI18N
                waistLabel.setLabelFor(waistMenu);
                waistLabel.setToolTipText("Waist");

                legsLabel.setFont(new java.awt.Font("Lucida Sans Typewriter", 0, 12));
                legsLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/legs.png"))); // NOI18N
                legsLabel.setLabelFor(legsMenu);
                legsLabel.setToolTipText("Legs");

                charmLabel.setFont(new java.awt.Font("Lucida Sans Typewriter", 0, 12));
                charmLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/charm.png"))); // NOI18N
                charmLabel.setLabelFor(charmMenu);
                charmLabel.setToolTipText("Charm");

                charmSkillLabel.setFont(new java.awt.Font("Monospaced", 0, 12));
                charmSkillLabel.setLabelFor(charmSkill1);
                charmSkillLabel.setText("Charm Skill");

                weaponSlot1.setFont(new java.awt.Font("Monospaced", 0, 12));
                weaponSlot1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                weaponSlot1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                weaponSlot1ActionPerformed(evt);
                        }
                });

                weaponSlot2.setFont(new java.awt.Font("Monospaced", 0, 12));
                weaponSlot2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                weaponSlot2.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                weaponSlot2ActionPerformed(evt);
                        }
                });

                weaponSlot3.setFont(new java.awt.Font("Monospaced", 0, 12));
                weaponSlot3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                weaponSlot3.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                weaponSlot3ActionPerformed(evt);
                        }
                });

                headSlot1.setFont(new java.awt.Font("Monospaced", 0, 12));
                headSlot1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                headSlot1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                headSlot1ActionPerformed(evt);
                        }
                });

                headSlot2.setFont(new java.awt.Font("Monospaced", 0, 12));
                headSlot2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                headSlot2.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                headSlot2ActionPerformed(evt);
                        }
                });

                headSlot3.setFont(new java.awt.Font("Monospaced", 0, 12));
                headSlot3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                headSlot3.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                headSlot3ActionPerformed(evt);
                        }
                });

                chestSlot1.setFont(new java.awt.Font("Monospaced", 0, 12));
                chestSlot1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                chestSlot1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                chestSlot1ActionPerformed(evt);
                        }
                });

                chestSlot2.setFont(new java.awt.Font("Monospaced", 0, 12));
                chestSlot2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                chestSlot2.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                chestSlot2ActionPerformed(evt);
                        }
                });

                chestSlot3.setFont(new java.awt.Font("Monospaced", 0, 12));
                chestSlot3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                chestSlot3.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                chestSlot3ActionPerformed(evt);
                        }
                });

                armSlot1.setFont(new java.awt.Font("Monospaced", 0, 12));
                armSlot1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                armSlot1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                armSlot1ActionPerformed(evt);
                        }
                });

                armSlot2.setFont(new java.awt.Font("Monospaced", 0, 12));
                armSlot2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                armSlot2.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                armSlot2ActionPerformed(evt);
                        }
                });

                armSlot3.setFont(new java.awt.Font("Monospaced", 0, 12));
                armSlot3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                armSlot3.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                armSlot3ActionPerformed(evt);
                        }
                });

                waistSlot1.setFont(new java.awt.Font("Monospaced", 0, 12));
                waistSlot1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                waistSlot1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                waistSlot1ActionPerformed(evt);
                        }
                });

                waistSlot2.setFont(new java.awt.Font("Monospaced", 0, 12));
                waistSlot2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                waistSlot2.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                waistSlot2ActionPerformed(evt);
                        }
                });

                waistSlot3.setFont(new java.awt.Font("Monospaced", 0, 12));
                waistSlot3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                waistSlot3.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                waistSlot3ActionPerformed(evt);
                        }
                });

                legSlot1.setFont(new java.awt.Font("Monospaced", 0, 12));
                legSlot1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                legSlot1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                legSlot1ActionPerformed(evt);
                        }
                });

                legSlot2.setFont(new java.awt.Font("Monospaced", 0, 12));
                legSlot2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                legSlot2.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                legSlot2ActionPerformed(evt);
                        }
                });

                legSlot3.setFont(new java.awt.Font("Monospaced", 0, 12));
                legSlot3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                legSlot3.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                legSlot3ActionPerformed(evt);
                        }
                });

                charmSlot1.setFont(new java.awt.Font("Monospaced", 0, 12));
                charmSlot1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                charmSlot1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                charmSlot1ActionPerformed(evt);
                        }
                });

                charmSlot2.setFont(new java.awt.Font("Monospaced", 0, 12));
                charmSlot2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                charmSlot2.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                charmSlot2ActionPerformed(evt);
                        }
                });

                charmSlot3.setFont(new java.awt.Font("Monospaced", 0, 12));
                charmSlot3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                charmSlot3.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                charmSlot3ActionPerformed(evt);
                        }
                });

                charmSkill1.setFont(new java.awt.Font("Monospaced", 0, 12));
                charmSkill1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                charmSkill1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                charmSkill1ActionPerformed(evt);
                        }
                });

                charmSkill2.setFont(new java.awt.Font("Monospaced", 0, 12));
                charmSkill2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
                charmSkill2.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                charmSkill2ActionPerformed(evt);
                        }
                });

                skillPoint1.setFont(new java.awt.Font("Monospaced", 0, 12));
                skillPoint1.setLabelFor(charmSkill1);
                skillPoint1.setText("+10");

                skillPoint2.setFont(new java.awt.Font("Monospaced", 0, 12));
                skillPoint2.setLabelFor(charmSkill2);
                skillPoint2.setText("-10");

                org.jdesktop.layout.GroupLayout setupLayout = new org.jdesktop.layout.GroupLayout(setup);
                setup.setLayout(setupLayout);
                setupLayout.setHorizontalGroup(
                        setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(setupLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(setupLayout.createSequentialGroup()
                                                .add(weaponLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                        .add(setupLayout.createSequentialGroup()
                                                                .add(charmSkillLabel)
                                                                .add(18, 18, 18)
                                                                .add(charmSkill1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(skillPoint1)
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(charmSkill2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(skillPoint2))
                                                        .add(setupLayout.createSequentialGroup()
                                                                .add(weaponMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(weaponSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(weaponSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                                .add(6, 6, 6)
                                                                .add(weaponSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                                        .add(setupLayout.createSequentialGroup()
                                                .add(headLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(headMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(headSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(headSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(headSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(setupLayout.createSequentialGroup()
                                                .add(chestLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(chestMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(chestSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(chestSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(chestSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(setupLayout.createSequentialGroup()
                                                .add(armsLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(armsMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(armSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(armSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(armSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(setupLayout.createSequentialGroup()
                                                .add(waistLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(waistMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(waistSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(waistSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(waistSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(setupLayout.createSequentialGroup()
                                                .add(legsLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(legsMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(legSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(legSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(legSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(setupLayout.createSequentialGroup()
                                                .add(charmLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(charmMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(charmSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(charmSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(charmSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 120, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .addContainerGap(18, Short.MAX_VALUE))
                );
                setupLayout.setVerticalGroup(
                        setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(setupLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(setupLayout.createSequentialGroup()
                                                .add(5, 5, 5)
                                                .add(weaponLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                .add(weaponMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(weaponSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(weaponSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(weaponSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .add(18, 18, 18)
                                .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                .add(headMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(headSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(headSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(headSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(headLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(18, 18, 18)
                                .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(chestMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(chestLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                .add(chestSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(chestSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(chestSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .add(18, 18, 18)
                                .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(armsLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                .add(armsMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(armSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(armSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(armSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .add(18, 18, 18)
                                .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                .add(waistMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(waistSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(waistSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(waistSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(waistLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(18, 18, 18)
                                .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                .add(legsMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(legSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(legSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(legSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(legsLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(18, 18, 18)
                                .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(charmMenu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(charmLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                .add(charmSlot1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(charmSlot2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(charmSlot3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .add(18, 18, 18)
                                .add(setupLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                        .add(charmSkillLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(skillPoint1)
                                        .add(skillPoint2)
                                        .add(charmSkill1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(charmSkill2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(13, Short.MAX_VALUE))
                );

                output.setBorder(javax.swing.BorderFactory.createTitledBorder("Output"));

                outputGroup.add(text);
                text.setFont(new java.awt.Font("Monospaced", 0, 12));
                text.setSelected(true);
                text.setText("TEXT");
                text.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                textActionPerformed(evt);
                        }
                });

                outputGroup.add(html);
                html.setFont(new java.awt.Font("Monospaced", 0, 12));
                html.setText("HTML");
                html.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                htmlActionPerformed(evt);
                        }
                });

                outputGroup.add(code);
                code.setFont(new java.awt.Font("Monospaced", 0, 12));
                code.setText("Code");
                code.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                codeActionPerformed(evt);
                        }
                });

                saveOutput.setFont(new java.awt.Font("Monospaced", 1, 12));
                saveOutput.setText("Save");
                saveOutput.setToolTipText("Append set to data file");
                saveOutput.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                saveOutputActionPerformed(evt);
                        }
                });

                jTextData.setFont(new java.awt.Font("Monospaced", 0, 12));
                jTextData.setText("MyData");
                jTextData.setToolTipText("Input your save data ");

                jLabel1.setFont(new java.awt.Font("Monospaced", 0, 12));
                jLabel1.setText("Data File");

                org.jdesktop.layout.GroupLayout outputLayout = new org.jdesktop.layout.GroupLayout(output);
                output.setLayout(outputLayout);
                outputLayout.setHorizontalGroup(
                        outputLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(outputLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(text)
                                .add(18, 18, 18)
                                .add(html)
                                .add(18, 18, 18)
                                .add(code)
                                .add(18, 18, 18)
                                .add(jLabel1)
                                .add(29, 29, 29)
                                .add(jTextData, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(saveOutput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                                .addContainerGap())
                );
                outputLayout.setVerticalGroup(
                        outputLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, outputLayout.createSequentialGroup()
                                .add(outputLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                        .add(text)
                                        .add(html)
                                        .add(code)
                                        .add(saveOutput)
                                        .add(jTextData, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(jLabel1))
                                .add(117, 117, 117))
                );

                jScrollPreview.setForeground(javax.swing.UIManager.getDefaults().getColor("Panel.background"));
                jScrollPreview.setFont(new java.awt.Font("Monospaced", 0, 12));
                jScrollPreview.setHorizontalScrollBar(null);

                jTextPreview.setColumns(20);
                jTextPreview.setEditable(false);
                jTextPreview.setFont(new java.awt.Font("Monospaced", 0, 12));
                jTextPreview.setForeground(new java.awt.Color(1, 1, 1));
                jTextPreview.setRows(5);
                jTextPreview.setBorder(javax.swing.BorderFactory.createTitledBorder("Preview"));
                jTextPreview.setOpaque(false);
                jScrollPreview.setViewportView(jTextPreview);

                setNamePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Set Name"));

                jTextSetName.setFont(new java.awt.Font("Monospaced", 0, 12));
                jTextSetName.setText("Unnamed Set");
                jTextSetName.setToolTipText("Input set name, use enter to preview it now");
                jTextSetName.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                jTextSetNameActionPerformed(evt);
                        }
                });

                org.jdesktop.layout.GroupLayout setNamePanelLayout = new org.jdesktop.layout.GroupLayout(setNamePanel);
                setNamePanel.setLayout(setNamePanelLayout);
                setNamePanelLayout.setHorizontalGroup(
                        setNamePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, setNamePanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(jTextSetName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
                                .addContainerGap())
                );
                setNamePanelLayout.setVerticalGroup(
                        setNamePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(setNamePanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(jTextSetName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(13, Short.MAX_VALUE))
                );

                org.jdesktop.layout.GroupLayout calculatorLayout = new org.jdesktop.layout.GroupLayout(calculator);
                calculator.setLayout(calculatorLayout);
                calculatorLayout.setHorizontalGroup(
                        calculatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(calculatorLayout.createSequentialGroup()
                                .add(12, 12, 12)
                                .add(calculatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(setup, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 622, Short.MAX_VALUE)
                                        .add(output, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .add(calculatorLayout.createSequentialGroup()
                                                .add(rank, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(12, 12, 12)
                                                .add(hunterType, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(sex, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(setNamePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .add(6, 6, 6)
                                .add(jScrollPreview, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 586, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                );
                calculatorLayout.setVerticalGroup(
                        calculatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(calculatorLayout.createSequentialGroup()
                                .add(output, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 57, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(6, 6, 6)
                                .add(calculatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(rank, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(hunterType, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(sex, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(setNamePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(setup, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
                                .addContainerGap())
                        .add(jScrollPreview, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 536, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                );

                jTabbedPane1.addTab("<html><body><table width=\"100\">&nbsp;Calculator</table></body></html>", new javax.swing.ImageIcon(getClass().getResource("/pic/calculator.png")), calculator, ""); // NOI18N

                jScrollPreview2.setFont(new java.awt.Font("Monospaced", 0, 12));
                jScrollPreview2.setHorizontalScrollBar(null);

                jTextPreview2.setColumns(20);
                jTextPreview2.setEditable(false);
                jTextPreview2.setFont(new java.awt.Font("Monospaced", 0, 12));
                jTextPreview2.setForeground(new java.awt.Color(1, 1, 1));
                jTextPreview2.setRows(5);
                jTextPreview2.setBorder(javax.swing.BorderFactory.createTitledBorder("Preview"));
                jTextPreview2.setOpaque(false);
                jScrollPreview2.setViewportView(jTextPreview2);

                codeBook.setBorder(javax.swing.BorderFactory.createTitledBorder("Code Book"));

                codeBookName.setFont(new java.awt.Font("Monospaced", 0, 12));
                codeBookName.setText("MyData");

                codeBookLoad.setFont(new java.awt.Font("Monospaced", 1, 12)); // NOI18N
                codeBookLoad.setText("Load");
                codeBookLoad.setToolTipText("Load code book");
                codeBookLoad.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                codeBookLoadActionPerformed(evt);
                        }
                });

                codeBookSave.setFont(new java.awt.Font("Monospaced", 1, 12)); // NOI18N
                codeBookSave.setText("Save");
                codeBookSave.setToolTipText("Save code  book, overwrite the old file");
                codeBookSave.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                codeBookSaveActionPerformed(evt);
                        }
                });

                org.jdesktop.layout.GroupLayout codeBookLayout = new org.jdesktop.layout.GroupLayout(codeBook);
                codeBook.setLayout(codeBookLayout);
                codeBookLayout.setHorizontalGroup(
                        codeBookLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(codeBookLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(codeBookName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(codeBookLoad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 65, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(codeBookSave, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 65, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(12, 12, 12))
                );
                codeBookLayout.setVerticalGroup(
                        codeBookLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(codeBookLayout.createSequentialGroup()
                                .add(codeBookLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                        .add(codeBookName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(codeBookLoad)
                                        .add(codeBookSave))
                                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                );

                convert.setBorder(javax.swing.BorderFactory.createTitledBorder("Export Sets"));

                buttonGroup1.add(convertTEXT);
                convertTEXT.setFont(new java.awt.Font("Monospaced", 0, 12));
                convertTEXT.setSelected(true);
                convertTEXT.setText("TEXT");
                convertTEXT.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                convertTEXTActionPerformed(evt);
                        }
                });

                buttonGroup1.add(convertHTML);
                convertHTML.setFont(new java.awt.Font("Monospaced", 0, 12));
                convertHTML.setText("HTML");
                convertHTML.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                convertHTMLActionPerformed(evt);
                        }
                });

                Output.setFont(new java.awt.Font("Monospaced", 1, 12));
                Output.setText("Save & Export");
                Output.setToolTipText("Save code book, and output sets");
                Output.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                OutputActionPerformed(evt);
                        }
                });

                org.jdesktop.layout.GroupLayout convertLayout = new org.jdesktop.layout.GroupLayout(convert);
                convert.setLayout(convertLayout);
                convertLayout.setHorizontalGroup(
                        convertLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(convertLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(convertTEXT)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(convertHTML)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(Output, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                                .addContainerGap())
                );
                convertLayout.setVerticalGroup(
                        convertLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(convertLayout.createSequentialGroup()
                                .add(convertLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                        .add(convertTEXT)
                                        .add(convertHTML)
                                        .add(Output))
                                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                );

                jScrollPane1.setFont(new java.awt.Font("Monospaced", 0, 12));

                codeList.setBorder(javax.swing.BorderFactory.createTitledBorder("Code List"));
                codeList.setFont(new java.awt.Font("Monospaced", 0, 12));
                codeList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
                codeList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
                        public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                                codeListValueChanged(evt);
                        }
                });
                jScrollPane1.setViewportView(codeList);

                loadSetInteract.setFont(new java.awt.Font("Monospaced", 1, 12));
                loadSetInteract.setText("Load to Calculator");
                loadSetInteract.setToolTipText("Load the selected set");
                loadSetInteract.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                loadSetInteractActionPerformed(evt);
                        }
                });

                getSetInteract.setFont(new java.awt.Font("Monospaced", 1, 12)); // NOI18N
                getSetInteract.setText("Add from Calculator");
                getSetInteract.setToolTipText("Add the set below");
                getSetInteract.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                getSetInteractActionPerformed(evt);
                        }
                });

                deleteInteract.setFont(new java.awt.Font("Monospaced", 1, 12));
                deleteInteract.setText("Remove/Cut");
                deleteInteract.setToolTipText("Remvoe/cut the selected set (max 5) ");
                deleteInteract.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                deleteInteractActionPerformed(evt);
                        }
                });

                undoInteract.setFont(new java.awt.Font("Monospaced", 1, 12));
                undoInteract.setText("Paste");
                undoInteract.setToolTipText("Append the recently removed set (max 5)");
                undoInteract.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                undoInteractActionPerformed(evt);
                        }
                });

                org.jdesktop.layout.GroupLayout viewerLayout = new org.jdesktop.layout.GroupLayout(viewer);
                viewer.setLayout(viewerLayout);
                viewerLayout.setHorizontalGroup(
                        viewerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, viewerLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(viewerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(org.jdesktop.layout.GroupLayout.TRAILING, viewerLayout.createSequentialGroup()
                                                .add(codeBook, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(convert, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(viewerLayout.createSequentialGroup()
                                                .add(loadSetInteract, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(getSetInteract, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(deleteInteract, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(undoInteract, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 633, Short.MAX_VALUE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jScrollPreview2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 586, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                );
                viewerLayout.setVerticalGroup(
                        viewerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(viewerLayout.createSequentialGroup()
                                .add(viewerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                        .add(org.jdesktop.layout.GroupLayout.LEADING, viewerLayout.createSequentialGroup()
                                                .add(12, 12, 12)
                                                .add(viewerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                        .add(convert, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                        .add(codeBook, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 418, Short.MAX_VALUE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(viewerLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                        .add(loadSetInteract)
                                                        .add(getSetInteract)
                                                        .add(deleteInteract)
                                                        .add(undoInteract)))
                                        .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPreview2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 535, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                );

                jTabbedPane1.addTab("<html><body><table width=\"100\">&nbsp;&nbsp;&nbsp;Viewer</table></body></html>", new javax.swing.ImageIcon(getClass().getResource("/pic/viewer.png")), viewer, ""); // NOI18N

                org.jdesktop.layout.GroupLayout generatorLayout = new org.jdesktop.layout.GroupLayout(generator);
                generator.setLayout(generatorLayout);
                generatorLayout.setHorizontalGroup(
                        generatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(0, 1226, Short.MAX_VALUE)
                );
                generatorLayout.setVerticalGroup(
                        generatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(0, 535, Short.MAX_VALUE)
                );

                jTabbedPane1.addTab("<html><body><table width=\"100\">&nbsp;&nbsp;Generator</table></body></html>", new javax.swing.ImageIcon(getClass().getResource("/pic/generator.png")), generator, ""); // NOI18N

                jScrollAbout.setBorder(javax.swing.BorderFactory.createTitledBorder("About"));

                jEditorAbout.setContentType("text/html");
                jEditorAbout.setEditable(false);
                jEditorAbout.setText("<html>\n  <head>\n\n  </head>\n  <body>\n    <h2 align = \"center\">\n      MHAG :\n    </h2>\n  <h2 align = \"center\">\n       Monster Hunter Armor Generator\n    </h2>\n <p align = \"center\">v1.0 Final Release</p>\n <p align = \"center\">Release Date: 01/10/2011</p>\n<p align = \"center\">MHAG Project: <a href=\"http://code.google.com/p/mhag/\">code.google.com/p/mhag</a></p>\n<p align = \"center\">Proposed MHAG Set Database: <a href=\"http://mhag.wetpaint.com\">mhag.wetpaint.com</p>\n<p></p>\n<p align = \"center\">by Tifa@mh3</p>\n<p align = \"center\">Unity Member: <a href=\"http://www.capcom-unity.com/tifa@mh3\">www.capcom-unity.com/tifa@mh3</a></p>\n<p align = \"center\">Youtube Channel: <a href=\"http://www.youtube.com/mh3journey\">www.youtube.com/mh3journey</a></p>\n\n  </body>\n\n");
                jEditorAbout.setOpaque(false);
                jEditorAbout.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
                        public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
                                jEditorAboutHyperlinkUpdate(evt);
                        }
                });
                jScrollAbout.setViewportView(jEditorAbout);

                jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pic/logo.png"))); // NOI18N

                jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Help"));

                helpList.setBorder(javax.swing.BorderFactory.createEtchedBorder());
                helpList.setOpaque(false);
                helpList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
                        public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                                helpListValueChanged(evt);
                        }
                });
                jScrollHelpList.setViewportView(helpList);

                jScrollHelpText.setBorder(javax.swing.BorderFactory.createEtchedBorder());

                helpText.setColumns(20);
                helpText.setEditable(false);
                helpText.setFont(new java.awt.Font("DejaVu Sans", 0, 14)); // NOI18N
                helpText.setLineWrap(true);
                helpText.setRows(5);
                helpText.setWrapStyleWord(true);
                helpText.setMargin(new java.awt.Insets(6, 6, 6, 6));
                helpText.setOpaque(false);
                jScrollHelpText.setViewportView(helpText);

                org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
                jPanel1.setLayout(jPanel1Layout);
                jPanel1Layout.setHorizontalGroup(
                        jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .add(jScrollHelpList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(jScrollHelpText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
                                .addContainerGap())
                );
                jPanel1Layout.setVerticalGroup(
                        jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                        .add(jScrollHelpText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 472, Short.MAX_VALUE)
                                        .add(jScrollHelpList, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 472, Short.MAX_VALUE))
                                .addContainerGap())
                );

                org.jdesktop.layout.GroupLayout aboutLayout = new org.jdesktop.layout.GroupLayout(about);
                about.setLayout(aboutLayout);
                aboutLayout.setHorizontalGroup(
                        aboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(aboutLayout.createSequentialGroup()
                                .add(aboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(aboutLayout.createSequentialGroup()
                                                .addContainerGap()
                                                .add(jScrollAbout, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 444, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(aboutLayout.createSequentialGroup()
                                                .add(171, 171, 171)
                                                .add(jLabel2)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())
                );
                aboutLayout.setVerticalGroup(
                        aboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(aboutLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(aboutLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .add(aboutLayout.createSequentialGroup()
                                                .add(jScrollAbout, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(jLabel2)))
                                .addContainerGap())
                );

                jTabbedPane1.addTab("<html><body><table width=\"100\">&nbsp;&nbsp;&nbsp;About</table></body></html>", new javax.swing.ImageIcon(getClass().getResource("/pic/help-browser.png")), about); // NOI18N

                org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
                getContentPane().setLayout(layout);
                layout.setHorizontalGroup(
                        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 1238, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                );
                layout.setVerticalGroup(
                        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 625, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                );

                pack();
        }// </editor-fold>//GEN-END:initComponents

    private void bladeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bladeActionPerformed
	    // set to blademaster
	    if(set.getBlade() == true )return;

	    set.setBlade(true);
	    initSetup(set.getLowRank(), set.getBlade(), set.getFemale());
    }//GEN-LAST:event_bladeActionPerformed

    private void highRankActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_highRankActionPerformed
	    // set to high Rank
	    if(set.getLowRank() == false )return;

	    set.setLowRank(false);
	    initSetup(set.getLowRank(), set.getBlade(), set.getFemale());
    }//GEN-LAST:event_highRankActionPerformed

    private void lowRankActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lowRankActionPerformed
	    // set to Low Rank
	    if(set.getLowRank() == true )return;

	    set.setLowRank(true);
	    initSetup(set.getLowRank(), set.getBlade(), set.getFemale());
    }//GEN-LAST:event_lowRankActionPerformed

    private void gunnerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gunnerActionPerformed
	    // set to blademaster
	    if(set.getBlade() == false )return;

	    set.setBlade(false);
	    initSetup(set.getLowRank(), set.getBlade(), set.getFemale());
    }//GEN-LAST:event_gunnerActionPerformed

    private void maleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maleActionPerformed
	    // set to male
	    if(set.getFemale() == false )return;

	    set.setFemale(false);
	    // TODO get & keep armorID

	    changeGender(set.getLowRank(), set.getBlade(), set.getFemale());
    }//GEN-LAST:event_maleActionPerformed

    private void femaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_femaleActionPerformed
	    // set to female
	    if(set.getFemale() == true )return;

	    set.setFemale(true);
	    // TODO get & keep armorID

	    changeGender(set.getLowRank(), set.getBlade(), set.getFemale());
    }//GEN-LAST:event_femaleActionPerformed

    private void headMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_headMenuActionPerformed
	    armorMenuAction(0);
    }//GEN-LAST:event_headMenuActionPerformed

    private void chestMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chestMenuActionPerformed
	    armorMenuAction(1);
    }//GEN-LAST:event_chestMenuActionPerformed

    private void armsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_armsMenuActionPerformed
	    armorMenuAction(2);
    }//GEN-LAST:event_armsMenuActionPerformed

    private void waistMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_waistMenuActionPerformed
	    armorMenuAction(3);
    }//GEN-LAST:event_waistMenuActionPerformed

    private void legsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_legsMenuActionPerformed
	    armorMenuAction(4);
    }//GEN-LAST:event_legsMenuActionPerformed

    private void weaponMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_weaponMenuActionPerformed
	    weaponMenuAction();
    }//GEN-LAST:event_weaponMenuActionPerformed

    private void charmMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_charmMenuActionPerformed
	    charmMenuAction();
    }//GEN-LAST:event_charmMenuActionPerformed

    private void charmSkill1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_charmSkill1ActionPerformed
	    charmSkillAction(0);
    }//GEN-LAST:event_charmSkill1ActionPerformed

    private void charmSkill2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_charmSkill2ActionPerformed
	    charmSkillAction(1);
    }//GEN-LAST:event_charmSkill2ActionPerformed

    private void weaponSlot1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_weaponSlot1ActionPerformed
	    jewelSlotAction(5, 0);
    }//GEN-LAST:event_weaponSlot1ActionPerformed

    private void weaponSlot2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_weaponSlot2ActionPerformed
	    jewelSlotAction(5, 1);
    }//GEN-LAST:event_weaponSlot2ActionPerformed

    private void weaponSlot3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_weaponSlot3ActionPerformed
	    jewelSlotAction(5, 2);
    }//GEN-LAST:event_weaponSlot3ActionPerformed

    private void headSlot1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_headSlot1ActionPerformed
	    jewelSlotAction(0, 0);
    }//GEN-LAST:event_headSlot1ActionPerformed

    private void headSlot2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_headSlot2ActionPerformed
	    jewelSlotAction(0, 1);
    }//GEN-LAST:event_headSlot2ActionPerformed

    private void headSlot3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_headSlot3ActionPerformed
	    jewelSlotAction(0, 2);
    }//GEN-LAST:event_headSlot3ActionPerformed

    private void chestSlot1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chestSlot1ActionPerformed
	    jewelSlotAction(1, 0);
    }//GEN-LAST:event_chestSlot1ActionPerformed

    private void chestSlot2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chestSlot2ActionPerformed
	    jewelSlotAction(1, 1);
    }//GEN-LAST:event_chestSlot2ActionPerformed

    private void chestSlot3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chestSlot3ActionPerformed
	    jewelSlotAction(1, 2);
    }//GEN-LAST:event_chestSlot3ActionPerformed

    private void armSlot1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_armSlot1ActionPerformed
	    jewelSlotAction(2, 0);
    }//GEN-LAST:event_armSlot1ActionPerformed

    private void armSlot2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_armSlot2ActionPerformed
	    jewelSlotAction(2, 1);
    }//GEN-LAST:event_armSlot2ActionPerformed

    private void armSlot3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_armSlot3ActionPerformed
	    jewelSlotAction(2, 2);
    }//GEN-LAST:event_armSlot3ActionPerformed

    private void waistSlot1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_waistSlot1ActionPerformed
	    jewelSlotAction(3, 0);
    }//GEN-LAST:event_waistSlot1ActionPerformed

    private void waistSlot2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_waistSlot2ActionPerformed
	    jewelSlotAction(3, 1);
    }//GEN-LAST:event_waistSlot2ActionPerformed

    private void waistSlot3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_waistSlot3ActionPerformed
	    jewelSlotAction(3, 2);
    }//GEN-LAST:event_waistSlot3ActionPerformed

    private void legSlot1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_legSlot1ActionPerformed
	    jewelSlotAction(4, 0);
    }//GEN-LAST:event_legSlot1ActionPerformed

    private void legSlot2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_legSlot2ActionPerformed
	    jewelSlotAction(4, 1);
    }//GEN-LAST:event_legSlot2ActionPerformed

    private void legSlot3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_legSlot3ActionPerformed
	    jewelSlotAction(4, 2);
    }//GEN-LAST:event_legSlot3ActionPerformed

    private void charmSlot1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_charmSlot1ActionPerformed
	    jewelSlotAction(6, 0);
    }//GEN-LAST:event_charmSlot1ActionPerformed

    private void charmSlot2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_charmSlot2ActionPerformed
	    jewelSlotAction(6, 1);
    }//GEN-LAST:event_charmSlot2ActionPerformed

    private void charmSlot3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_charmSlot3ActionPerformed
	    jewelSlotAction(6, 2);
    }//GEN-LAST:event_charmSlot3ActionPerformed

    private void textActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textActionPerformed
	    saveOpt = 0;
    }//GEN-LAST:event_textActionPerformed

    private void htmlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_htmlActionPerformed
	    saveOpt = 1;
    }//GEN-LAST:event_htmlActionPerformed

    private void codeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_codeActionPerformed
	    saveOpt = 2;
}//GEN-LAST:event_codeActionPerformed

    private void saveOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveOutputActionPerformed
	    try {
		    appendData();
		    if(!fileNameData.equals(jTextData.getText())) //name changed,save pref
		    {
			    fileNameData = jTextData.getText();
			    savePref();
		    }
	    } catch (FileNotFoundException ex) {
		    Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
	    }
}//GEN-LAST:event_saveOutputActionPerformed

    private void codeBookLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_codeBookLoadActionPerformed

	    String codeFile = codeBookName.getText();
	    if(!codeFile.endsWith(".code"))
		    codeFile = codeFile+".code";

	    Scanner codeIn;

		try {
			codeIn = new Scanner(new File(codeFile));
		} catch (FileNotFoundException ex) {
			String message = String.format("Code File %s doesnot exist!\n",codeFile);
			jTextPreview2.append(message);
			message = String.format("create a new Code Book %s, or choose another Code File\n",codeFile);
			jTextPreview2.append(message);
			return;
		}

	    listModel.clear();
	    while(codeIn.hasNext())
	    {
		    String codeLine = codeIn.nextLine();
		    listModel.addElement(codeLine);
	    }

	    adjust = true;
	    codeList.setModel(listModel);
	    codeList.clearSelection();
	    adjust = false;

	    codeIn.close();
	    codeBookInUse = true;
	    jTextPreview2.setText("");  //clear Preview when loading codebook

	    if(!fileNameCodeBook.equals(codeBookName.getText())) //name changed,save pref
		    try {
		        fileNameCodeBook = codeBookName.getText();
			savePref();
		} catch (FileNotFoundException ex) {
			Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
		}

    }//GEN-LAST:event_codeBookLoadActionPerformed

    private void codeBookSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_codeBookSaveActionPerformed
		try {
			codeBookSave();
			codeBookChanged = false;  // reset book change status

		        if(!fileNameCodeBook.equals(codeBookName.getText())) //name changed,save pref
			{
				fileNameCodeBook = codeBookName.getText();
				savePref();
			}

		} catch (FileNotFoundException ex) {
			Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
		}
    }//GEN-LAST:event_codeBookSaveActionPerformed

    private void codeBookSave() throws FileNotFoundException
    {
	    //ListModel listModel =  codeList.getModel();
	    int num = listModel.getSize();
	    if(num == 0)
	    {
		    jTextPreview2.setText("Don't have any code! Why save it?!\n");
		    return;
	    }

	    String codeFile = codeBookName.getText();
	    PrintStream codeOut;
	    if(!codeFile.endsWith(".code"))
		    codeFile = codeFile+".code";

	    codeOut = new PrintStream(codeFile);

	    for(int i = 0; i < num; i++)
	    {
		    String codeLine = (String) listModel.getElementAt(i);
		    codeOut.println(codeLine);
	    }

    }

    private void convertTEXTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertTEXTActionPerformed
	    saveOpt = 0;
    }//GEN-LAST:event_convertTEXTActionPerformed

    private void convertHTMLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertHTMLActionPerformed
	    saveOpt = 1;
    }//GEN-LAST:event_convertHTMLActionPerformed

    private void OutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OutputActionPerformed

		try {
			codeBookSave();
			codeBookChanged = false;  // reset book change status

		        if(!fileNameCodeBook.equals(codeBookName.getText())) //name changed,save pref
			{
				fileNameCodeBook = codeBookName.getText();
				savePref();
			}
		} catch (FileNotFoundException ex) {
			Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
		}

	    String codeFile = codeBookName.getText();
	    String saveFile = "";
	    PrintStream codeOut;
	    if(!codeFile.endsWith(".code"))
	    {
		    if(saveOpt == 0)
			    saveFile = codeFile+".txt";
		    else
			    saveFile = codeFile+".html";

		    codeFile = codeFile+".code";
	    }
	    else
	    {
		    int pos = codeFile.indexOf(".code");
		    String codePart = codeFile.substring(0,pos);
		    if(saveOpt == 0)
			    saveFile = codePart+".txt";
		    else
			    saveFile = codePart+".html";
	    }

	    mhag.setFileIn(codeFile);
	    mhag.setFileOut(saveFile);
	    mhag.setOutFormat(saveOpt);

		try {
			mhagData.batchCalc(mhag);  //use batch calculator module
		} catch (FileNotFoundException ex) {
			Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
		}
	    mhag.setOutFormat(0); //back to text format

    }//GEN-LAST:event_OutputActionPerformed

    private void codeListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_codeListValueChanged
	    if(!evt.getValueIsAdjusting()) //solve the problem of running twice !
		    codePreview();
    }//GEN-LAST:event_codeListValueChanged

    private void loadSetInteractActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadSetInteractActionPerformed
	    if(!codeBookInUse)return;
	    String setCode = (String) codeList.getSelectedValue();
	    loadSet2Calc(setCode);
    }//GEN-LAST:event_loadSetInteractActionPerformed

    private void getSetInteractActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getSetInteractActionPerformed
	    //read set name, in case users input it , but foget to 'set' it 
	    //by 'enter' key and not adjusting with other options
	    String setName = jTextSetName.getText();
	    set.setSetName(setName);

	    String codeLine = set.getSetCode();
	    int ind = codeList.getSelectedIndex();
	    listModel.insertElementAt(codeLine, ind+1);
	    codeList.setSelectedIndex(ind+1);

	    codeBookChanged = true;  //insert the set , so mark it changed
    }//GEN-LAST:event_getSetInteractActionPerformed

    private void deleteInteractActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteInteractActionPerformed
	    int ind = codeList.getSelectedIndex();

	    //save deleted code;
	    String codeLine = (String) codeList.getSelectedValue();
	    for(int i = 4; i > 0; i--)
		    deletedCodes[i] = deletedCodes[i-1];
	    deletedCodes[0] = codeLine;

	    //remove code element
	    listModel.removeElementAt(ind);

	    //move index
	    int indNext;
	    if(listModel.size() == ind)
		    indNext = ind - 1;
	    else
		    indNext = ind;
	    codeList.setSelectedIndex(indNext);

	    codeBookChanged = true;  //delete the set , so mark it changed
    }//GEN-LAST:event_deleteInteractActionPerformed

    private void jTextSetNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextSetNameActionPerformed
	    String setName = jTextSetName.getText();
	    set.setSetName(setName);
	    calSetGUI();
    }//GEN-LAST:event_jTextSetNameActionPerformed

    private void undoInteractActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_undoInteractActionPerformed
	    //append deleted code
	    String codeLine = deletedCodes[0];
	    if(codeLine.equals(""))return; // Don't append empty code

	    int ind = codeList.getSelectedIndex();
	    listModel.insertElementAt(codeLine, ind+1);
	    codeList.setSelectedIndex(ind+1);

	    //remove the code from the list ofdeleted codes
	    for(int i = 0; i < 4; i++)
		    deletedCodes[i] = deletedCodes[i+1];
	    deletedCodes[4] = "";

	    /*for(int i = 0; i < 5; i++)
		    System.out.println("here:"+deletedCodes[i]);
	    System.out.println("========================");
	     */

	    codeBookChanged = true;  //paste the set , so mark it changed
    }//GEN-LAST:event_undoInteractActionPerformed

    private void jEditorAboutHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {//GEN-FIRST:event_jEditorAboutHyperlinkUpdate
		try {
			launchBrowser(evt);
		} catch (URISyntaxException ex) {
			Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
		} catch (IOException ex) {
			Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
		}
    }//GEN-LAST:event_jEditorAboutHyperlinkUpdate

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
	    if(!codeBookChanged)return;

	SaveAndExit dialog = new SaveAndExit(new javax.swing.JFrame(), true);
	dialog.setLocationRelativeTo(codeBookSave);
	dialog.setVisible(true);

	if(dialog.getReturnStatus() == 1)
	{
		try {
			codeBookSave();
		        if(!fileNameCodeBook.equals(codeBookName.getText())) //name changed,save pref
			{
				fileNameCodeBook = codeBookName.getText();
				savePref();
			}
		} catch (FileNotFoundException ex) {
			Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
		}
	}

    }//GEN-LAST:event_formWindowClosing

    private void helpListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_helpListValueChanged

	    int ind = helpList.getSelectedIndex();

	    if(ind < 0) return; //not initiate;

	    helpText.setText(helpData[ind]);

    }//GEN-LAST:event_helpListValueChanged

    private void launchBrowser(HyperlinkEvent evt) throws URISyntaxException, IOException
    {
	    HyperlinkEvent.EventType type = evt.getEventType();
	    if (type == HyperlinkEvent.EventType.ACTIVATED)
	    {
		    StringTokenizer st = new StringTokenizer(evt.getDescription());
		    if(st.hasMoreTokens())
		    {
			    String urlString = st.nextToken();
			    if(Desktop.isDesktopSupported())
			    {
				    URI uri = new URI(urlString);
				    Desktop.getDesktop().browse(uri);
			    }
		    }
	    }

    }

    private void codePreview()
    {
	    if(adjust) return; //when loading code book
	    if(codeList.getSelectedIndex() < 0) return; //not initiate;

	    streamView.reset();

	    String setCode = (String) codeList.getSelectedValue();

	    Set aSet = new Set();

	    boolean pass = true;
	    pass = aSet.setSetFromCode(mhag, setCode); //read set

	    if(pass)
		    pass = aSet.checkSet(mhag, mhagData);  //check set
	    if(!pass)
	    {
		    jTextPreview2.setText("Error in set code!\n");
		    return;
	    }
	    aSet.calcSet(mhag, mhagData);   //calculate set

	    mhag.setOutFormat(0);
	    aSet.save(mhag, mhagData, streamView);  // save results
	    streamView.rewind();

    }


    private void loadSet2Calc(String setCode)
    {
	    Set aSet = new Set();

	    boolean pass = true;
	    pass = aSet.setSetFromCode(mhag, setCode); //read set

	    if(pass)
		    pass = aSet.checkSet(mhag, mhagData);  //check set

	    if(!pass)
	    {
		    jTextPreview2.append("Forbid loading wrong code to calculator!\n");
		    return;
	    }

	    initGUISet();

	    // start load
	    jTextSetName.setText(aSet.getSetName());

	    if(aSet.getLowRank())
	    {
		    lowRank.setSelected(true);
		    highRank.setSelected(false);
	    }
	    else
	    {
		    lowRank.setSelected(false);
		    highRank.setSelected(true);
	    }

	    if(aSet.getBlade())
	    {
		    blade.setSelected(true);
		    gunner.setSelected(false);
	    }
	    else
	    {
		    blade.setSelected(false);
		    gunner.setSelected(true);
	    }

	    male.setSelected(true);
	    female.setSelected(false);

	    set.setBlade(aSet.getBlade());
	    set.setLowRank(aSet.getLowRank());
	    set.setFemale(aSet.getFemale());

	    initSetup(aSet.getLowRank(), aSet.getBlade(), false);

	    //weapon menu
	    int nJewel = aSet.getNumJewel(5);
	    int nSlot = 0;
	    for(int i = 0; i < nJewel; i++)
		    nSlot += mhagData.getJewel(aSet.getJewelID()[5][i]).getNumSlot();

	    weaponMenu.setSelectedIndex(nSlot);
	    weaponMenuAction();

	    //body menu
	    for (int i = 0; i < 5; i++)
	    {
		    int armorID = aSet.getArmorID()[i];
		    JComboBox bodyMenu = getArmorMenuObj(i);

		    if(!aSet.getInUse(i))
		    {
			    bodyMenu.setSelectedIndex(0);
			    armorMenuAction(i);
		    }
		    else
		    {
			    int[] list = mhagData.getArmorList(aSet.getLowRank(),
				   aSet.getBlade(), false, i);
			    for (int j = 0; j < list.length; j++)
			    {
				    if(list[j] == armorID)
				    {
					    bodyMenu.setSelectedIndex(j);
					    armorMenuAction(i);
					    break;
				    }
			    }
		    }
	    }

	    //charm menu
	    int[] list2;
	    if(!aSet.getInUse(6))
	    {
		    charmMenu.setSelectedIndex(0);
		    charmMenuAction();
	    }
	    else
	    {
		    list2 = mhagData.getCharmList(aSet.getLowRank());

		    for (int j = 0; j < list2.length; j++)
		    {
			    if(list2[j] == aSet.getCharmID())
			    {
				    charmMenu.setSelectedIndex(j);
				    charmMenuAction();
				    break;
			    }
		    }
	    }

	    //jewel menu
	    for(int i = 0; i< 7; i++)
	    {
		    for(int j = 0; j < aSet.getNumJewel(i); j++)
		    {
			    int jewelID = aSet.getJewelID()[i][j];
			    JComboBox jewelSlot = getJewelSlotObj(i,j);

			    int[] list = mhagData.getJewelList(aSet.getLowRank(),
				    jewelMenuType[i][j]);
			    for (int k = 0; k < list.length; k++)
			    {
				    if(list[k] == jewelID)
				    {
					    jewelSlot.setSelectedIndex(k);
					    jewelSlotAction(i,j);
					    break;
				    }
			    }

		    }
	    }

	    //charm skill
	    int nSkill = aSet.getNumCharmSkill();
	    if(nSkill == 1)
	    {
		    Charm charm = mhagData.getCharm(aSet.getCharmID());
		    list2 = mhagData.getSkillList(charm.getSkillClass()[0],
			   set.getCharmSkillID()[1]);

		    for (int j = 0; j < list2.length; j++)
		    {
			    if(list2[j] == aSet.getCharmSkillID()[0])
			    {
				    charmSkill1.setSelectedIndex(j);
				    charmSkillAction(0);
				    break;
			    }
		    }
	    }
	    else if(nSkill == 2)
	    {
		    Charm charm = mhagData.getCharm(aSet.getCharmID());
		    //check the 1st skill, if not available, move 2nd skill

		    list2 = mhagData.getSkillList(charm.getSkillClass()[0],
			   set.getCharmSkillID()[1]);

		    boolean found = false;
		    for (int j = 0; j < list2.length; j++)
		    {
			    if(list2[j] == aSet.getCharmSkillID()[0])
			    {
				    charmSkill1.setSelectedIndex(j);
				    charmSkillAction(0);
				    found = true;
				    break;
			    }
		    }

		    if(!found)
		    {
			    int ind = charmSkill2.getSelectedIndex();
			    charmSkill2.setSelectedIndex(ind + 1);
			    charmSkillAction(1);

			    //redo 1st skill

			    list2 = mhagData.getSkillList(charm.getSkillClass()[0],
				   aSet.getCharmSkillID()[1]);
			    for (int j = 0; j < list2.length; j++)
			    {
				    if(list2[j] == aSet.getCharmSkillID()[0])
				    {
					    charmSkill1.setSelectedIndex(j);
					    charmSkillAction(0);
					    break;
				    }
			    }
		    }

		    //check 2st skill

		    list2 = mhagData.getSkillList(charm.getSkillClass()[1],
			   aSet.getCharmSkillID()[0]);
		    for (int j = 0; j < list2.length; j++)
		    {
			    if(list2[j] == aSet.getCharmSkillID()[1])
			    {
				    charmSkill2.setSelectedIndex(j);
				    charmSkillAction(1);
				    break;
			    }
		    }

	    }


    }

    private void appendData() throws FileNotFoundException
    {
	    calSetGUI();
	    PrintStream saveStream;
	    String saveData = jTextData.getText();
	    if(saveOpt == 0) //text file
	    {
		    if(!saveData.endsWith(".txt"))
			    saveData = saveData + ".txt";
		    saveStream = MhagUtil.streamAppendFile(saveData);
		    mhag.setOutFormat(0);
		    set.save(mhag, mhagData, saveStream);  // save results

	    }
	    else if (saveOpt == 1)
	    {
		    if(!saveData.endsWith(".html"))
			    saveData = saveData + ".html";
		    saveStream = MhagUtil.streamAppendFile(saveData);
		    mhag.setOutFormat(1);

		    saveStream.printf("<p style=\"page-break-before:always\">" +
				"Set :</p>\n");
		    set.save(mhag, mhagData, saveStream);  // save results

		    mhag.setOutFormat(0);

	    }
	    else
	    {
		    if(!saveData.endsWith(".code"))
			    saveData = saveData + ".code";
		    saveStream = MhagUtil.streamAppendFile(saveData);
		    String codeLine = set.getSetCode();   //get set code
		    saveStream.println(codeLine);
	    }
	    saveStream.close();

    }

    private void weaponMenuAction()
    {
	   int ind = weaponMenu.getSelectedIndex();
	   int bodyPart = 5;

	   if(ind <= 0 )
	   {
		   set.setInUse(bodyPart, false);
		   set.setNumJewel(bodyPart, 0);  //initiate jewel
		   Arrays.fill(jewelInd[bodyPart], 0);  // inititate jewelInd
		   Arrays.fill(jewelMenuType[bodyPart], 0);  // inititate menu type
		   for (int i = 0; i < 3; i++)
		   {
			   changeJewelSlot(bodyPart, i, set.getLowRank(), 0, false);
		   }
		   calSetGUI();
	   }
	   else
	   {
		   set.setInUse(bodyPart, true);

		   // get number of slots
		   int nSlot = ind;
		   //initialiate jewel menu lists
		   set.setNumJewel(bodyPart, nSlot);
		   Arrays.fill(jewelInd[bodyPart], 0);  // inititate jewelInd
		   for (int i = 0; i < nSlot; i++)  //start from 1
		   {
			   changeJewelSlot(bodyPart, i, set.getLowRank(), nSlot, true);
		   }
		   for (int i = nSlot; i < 3; i++)
		   {
			   changeJewelSlot(bodyPart, i, set.getLowRank(), 0, false);
		   }

	   }

    }

    private void armorMenuAction(int bodyPart)
    {
	    if(adjust)return;  //for male/female change

	   JComboBox bodyMenu = getArmorMenuObj(bodyPart);

	   int ind = bodyMenu.getSelectedIndex();

	   if(ind <= 0 )
	   {
		   set.setInUse(bodyPart, false);
		   set.setNumJewel(bodyPart, 0);  //initiate jewel
		   Arrays.fill(jewelInd[bodyPart], 0);  // inititate jewelInd
		   Arrays.fill(jewelMenuType[bodyPart], 0);  // inititate menu type
		   for (int i = 0; i < 3; i++)  //start from 1
			   changeJewelSlot(bodyPart, i, set.getLowRank(), 0, false);
		   calSetGUI();
	   }
	   else
	   {
		   // obtain list value
		   int[] list = mhagData.getArmorList(set.getLowRank(),
			   set.getBlade(), set.getFemale(), bodyPart);
		   int armorID = list[ind];
		   if(armorID == set.getArmorID()[bodyPart])return; //no change, no reset

		   // set armor id
		   set.setInUse(bodyPart, true);
		   set.setArmorID(bodyPart, armorID);

		   // get number of slots
		   Armor armor = mhagData.getArmor(bodyPart, armorID);
		   int nSlot = armor.getNumSlot();
		   //initialiate jewel menu lists
		   set.setNumJewel(bodyPart, nSlot);
		   Arrays.fill(jewelInd[bodyPart], 0);  // inititate jewelInd
		   for (int i = 0; i < nSlot; i++)  //start from 1
		   {
			   changeJewelSlot(bodyPart, i, set.getLowRank(), nSlot, true);
		   }
		   for (int i = nSlot; i < 3; i++)
		   {
			   changeJewelSlot(bodyPart, i, set.getLowRank(), 0, false);
		   }

		   if(nSlot == 0)calSetGUI();
	   }
    }

    private void charmMenuAction()
    {
	   int ind = charmMenu.getSelectedIndex();
	   int bodyPart = 6;

	   if(ind <= 0 )
	   {
		   set.setInUse(bodyPart, false);
		   set.setNumJewel(bodyPart, 0);  //initiate jewel
		   Arrays.fill(jewelInd[bodyPart], 0);  // inititate jewelInd
		   Arrays.fill(jewelMenuType[bodyPart], 0);  // inititate menu type
		   for (int i = 0; i < 3; i++)   //change charm jewel
			   changeJewelSlot(bodyPart, i, set.getLowRank(), 0, false);
		   for (int i = 0; i < 2; i++)  //change charm skill
			   changeCharmSkill(i, "D", false);
		   charmSkillLabel.setVisible(false);
		   skillPoint1.setText("");
		   skillPoint2.setText("");
		   set.setCharmID(-1);
		   set.setNumCharmSkill(0);
		   set.setCharmSkillID(0, -1);
		   set.setCharmSkillID(1, -1);
	   }
	   else
	   {
		   //obtain list value
		   int[] list = mhagData.getCharmList(set.getLowRank());
		   int charmID = list[ind];
		   if(set.getCharmID() == charmID)return; // no change

		   // set Jewel id
		   set.setInUse(bodyPart, true);
		   set.setCharmID(charmID);

		   // get number of slots
		   Charm charm = mhagData.getCharm(charmID);
		   int nSlot = charm.getNumSlot();
		   //initialiate jewel menu lists
		   set.setNumJewel(bodyPart, nSlot);
		   Arrays.fill(jewelInd[bodyPart], 0);  // inititate jewelInd
		   for (int i = 0; i < 3; i++) //start from 1
		   {
			   if(i < nSlot)
			   {
				   changeJewelSlot(bodyPart, i, set.getLowRank(), nSlot, true);
			   }
			   else
			   {
				   changeJewelSlot(bodyPart, i, set.getLowRank(), 0, false);
			   }
		   }
		   //change charmSkill

		   int nSkill = charm.getNumSkill();
		   set.setNumCharmSkill(nSkill);

		   if(nSkill == 1)
		   {
			   set.setCharmSkillID(1, -1);
			   charmSkillLabel.setVisible(true);
			   String skillClass = charm.getSkillClass()[0];
			   changeCharmSkill(0, skillClass, true);
			   skillPoint1.setText(String.format(
				   "%+d",charm.getSkillPoint()[0]));
			   changeCharmSkill(1, "D", false);
			   skillPoint2.setText("");

		   }
		   else if(nSkill == 2)
		   {
			   charmSkillLabel.setVisible(true);
			   String skillClass = charm.getSkillClass()[0];
			   changeCharmSkill(0, skillClass, true);
			   skillPoint1.setText(String.format(
				   "%+d",charm.getSkillPoint()[0]));
			   skillClass = charm.getSkillClass()[1];
			   changeCharmSkill(1, skillClass, true);
			   skillPoint2.setText(String.format(
				   "%+d",charm.getSkillPoint()[1]));
		   }
		   else
		   {
			   set.setCharmSkillID(0, -1);
			   set.setCharmSkillID(1, -1);
			   charmSkillLabel.setVisible(false);
			   changeCharmSkill(0, "D", false);
			   skillPoint1.setText("");
			   changeCharmSkill(1, "D", false);
			   skillPoint2.setText("");
		   }

	   }
	   calSetGUI();
    }

    private void charmSkillAction(int slotInd)
    {
	    if(adjust)return;
	    if(slotInd == 0)
	    {
		   //charm skill 1
		   int ind = charmSkill1.getSelectedIndex();
		   if(ind < 0) return;

		   Charm charm = mhagData.getCharm(set.getCharmID());
		   int[] list = mhagData.getSkillList(charm.getSkillClass()[0],
			   set.getCharmSkillID()[1]);

		   set.setCharmSkillID(0,list[ind]);

		   if(set.getNumCharmSkill() == 2)
		   {
			   adjust = true;
			   Charm charm2 =  mhagData.getCharm(set.getCharmID());
			   changeCharmSkill(1, charm2.getSkillClass()[1], true);
			   adjust = false;
		   }
	    }
	    else
	    {
		    //charm skill 2
		   int ind = charmSkill2.getSelectedIndex();
		   if(ind < 0) return;

		   Charm charm = mhagData.getCharm(set.getCharmID());
		   int[] list = mhagData.getSkillList(charm.getSkillClass()[1],
			   set.getCharmSkillID()[0]);

		   set.setCharmSkillID(1,list[ind]);

		   if(set.getNumCharmSkill() == 2)
		   {
			   adjust = true;
			   Charm charm2 =  mhagData.getCharm(set.getCharmID());
			   changeCharmSkill(0, charm2.getSkillClass()[0], true);
			   adjust = false;
		   }
	    }
	    calSetGUI();
    }

    private void jewelSlotAction(int bodyPart, int slotInd)
    {
	   if(adjust)return;  //don't perform action, when adjust combo box list;

	   JComboBox jewelSlot = getJewelSlotObj(bodyPart, slotInd);

	   int ind = jewelSlot.getSelectedIndex();
	   if(ind < 0) return; //initial menu

	   jewelInd[bodyPart][slotInd] = ind;

	   // change the other 2 comboBox

	   adjust = true;
	   int nSlot;
	   if(bodyPart < 5) // armor piece
	   {
		   Armor armor = mhagData.getArmor(bodyPart, set.getArmorID()[bodyPart]);
		   nSlot = armor.getNumSlot();  //armor slot
	   }
	   else if(bodyPart == 5) //weapon
	   {
		   nSlot = weaponMenu.getSelectedIndex();
	   }
	   else // charm
	   {
		   Charm charm = mhagData.getCharm(set.getCharmID());
		   nSlot = charm.getNumSlot();
	   }

	   //special case [2/1/0]
  	   boolean match = check200(bodyPart, nSlot);

//	   boolean match = false;
	   if(!match)
	   {
		   for (int i = 0; i < nSlot; i++)
		   {
			   if(i == slotInd)continue;
			   int nRest = nSlot - restSlots(bodyPart, i);

			   if(nRest <= 0)
			   {
				   changeJewelSlot(bodyPart, i, set.getLowRank(), 0, false);
			   }
			   else
			   {
				   changeJewelSlot(bodyPart, i, set.getLowRank(), nRest, true);
			   }

		   }
	    }
//	   getJewel(bodyPart);

	   setJewelGUI(bodyPart);
	   calSetGUI();
//	   System.out.printf(">> %s %s %s\n",jewelMenuType[bodyPart][0],jewelMenuType[bodyPart][1],jewelMenuType[bodyPart][2]);
//	   System.out.printf("> %s %s %s\n",jewelInd[bodyPart][0],jewelInd[bodyPart][1],jewelInd[bodyPart][2]);

	   adjust = false;

    }

    // get Jewel ID according to jewel buttton position
    private void getJewelID(int bodyPart)
    {
	    int[] jewelID = new int[3];
	    Arrays.fill(jewelID,-1);
	    for (int i = 0; i < 3; i++)
	    {
		    int ind = jewelInd[bodyPart][i];
		    if(ind <= 0)continue;
		    int[] list = mhagData.getJewelList(set.getLowRank(), jewelMenuType[bodyPart][i]);
		    jewelID[i] = list[ind];
	    }
    }

    // [2/0/0] slot menu case, only show 2/1
    private boolean check200(int bodyPart, int Slot)
    {
	    if(Slot != 3) return false;

	    boolean if2Slot = false;
	    int[] indLeft = new int[3];
	    Arrays.fill(indLeft, -1);
	    int ind2nd = -1;

	    int j = 0;
	    for (int i = 0; i < 3; i++)
	    {
		    int[] list = mhagData.getJewelList(set.getLowRank(), jewelMenuType[bodyPart][i]);
		    int ind = jewelInd[bodyPart][i];
		    if(ind <= 0)
		    {
			    indLeft[j++] = i;
			    continue;
		    }
		    int nSlot = mhagData.getJewel(list[ind]).getNumSlot();
		    if(nSlot == 2)
		    {
			    if2Slot = true;
			    ind2nd = i;
		    }
		    else
			    return false;
	    }
	    if(if2Slot )  // 2 & 0 & (0)
	    {
		    changeJewelSlot(bodyPart, ind2nd, set.getLowRank(), 3, true);
		    changeJewelSlot(bodyPart, indLeft[0], set.getLowRank(), 1, true);
		    changeJewelSlot(bodyPart, indLeft[1], set.getLowRank(), 0, false);
		    return true;
	    }
	    else
		    return false;
    }

    private int restSlots(int bodyPart, int slotInd)
    {
	    int num = 0;
	    for(int i = 0; i < 3; i++)
	    {
		    if(slotInd == i)continue;
		    int ind = jewelInd[bodyPart][i];
		    if(ind <= 0)continue;
		    int[] list = mhagData.getJewelList(set.getLowRank(), jewelMenuType[bodyPart][i]);
		    int jewelID = list[ind];
		    num += mhagData.getJewel(jewelID).getNumSlot();
	    }
	    return num;
    }

    private void setJewelGUI(int bodyPart)
    {

	   int nJewel = 0;
	   for(int i = 0; i < 3; i++)
	   {
		   int ind = jewelInd[bodyPart][i];
		   if(ind <=0 ) continue;
		   int[] list = mhagData.getJewelList(set.getLowRank(), jewelMenuType[bodyPart][i]);
		   set.setJewelID(bodyPart, nJewel, list[ind]);
		   nJewel++;
	   }
	   set.setNumJewel(bodyPart, nJewel);
    }


    private void initMhag() throws FileNotFoundException
    {
	mhag.setMethod(0);  // default method: calculator
	//mhag.setLogOpt(0);  // log in console screen
	mhag.setLogOpt(2);  // turn off log
	mhag.prepareLogFile();

	mhag.showMhagInfo(); //display MHAG welcome info
	mhagData.readFile(mhag); //read file
	mhagData.dataPreProc();  //pre process

	Arrays.fill(deletedCodes, ""); //initiate deleted codes

	initGUISet();

    }

    private void initGUISet()
    {
	set.init();
	for (int i = 0; i < 7; i++)
	{
		Arrays.fill(jewelInd[i],0);   // init jewel IDs as null
		Arrays.fill(jewelMenuType[i],0);   // init jewel IDs as null
	}

	//initialize renderer
	for(int i = 0; i < 7; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			renderer[i][j] = new ComboboxToolTipRenderer();
		        JComboBox jewelSlot = getJewelSlotObj(i, j);
			jewelSlot.setRenderer(renderer[i][j]);
		}
	}

	for(int i = 0; i < 5; i++)
	{
		rendererArmor[i] = new ComboboxToolTipRenderer();
		JComboBox bodyMenu = getArmorMenuObj(i);
		bodyMenu.setRenderer(rendererArmor[i]);
	}

    }

    /**
    * @param args the command line arguments
    */

    public JComboBox getArmorMenuObj(int bodyPart)
    {
	    JComboBox bodyMenu;
	    if(bodyPart == 0)
		    bodyMenu = headMenu;
	    else if(bodyPart == 1)
		    bodyMenu = chestMenu;
	    else if(bodyPart == 2)
		    bodyMenu = armsMenu;
	    else if(bodyPart == 3)
		    bodyMenu = waistMenu;
	    else
		    bodyMenu = legsMenu;

	    return bodyMenu;
    }

    public JComboBox getJewelSlotObj(int bodyPart, int slotInd)
    {
	    JComboBox jewelSlot;
	    if(bodyPart == 0)
	    {
		    if(slotInd == 0)
		    {
			    jewelSlot = headSlot1;
		    }
		    else if(slotInd == 1)
		    {
			    jewelSlot = headSlot2;
		    }
		    else
		    {
			    jewelSlot = headSlot3;
		    }
	    }
	    else if(bodyPart == 1)
	    {
		    if(slotInd == 0)
		    {
			    jewelSlot = chestSlot1;
		    }
		    else if(slotInd == 1)
		    {
			    jewelSlot = chestSlot2;
		    }
		    else
		    {
			    jewelSlot = chestSlot3;
		    }
	    }
	    else if(bodyPart == 2)
	    {
		    if(slotInd == 0)
		    {
			    jewelSlot = armSlot1;
		    }
		    else if(slotInd == 1)
		    {
			    jewelSlot = armSlot2;
		    }
		    else
		    {
			    jewelSlot = armSlot3;
		    }
	    }
	    else if(bodyPart == 3)
	    {
		    if(slotInd == 0)
		    {
			    jewelSlot = waistSlot1;
		    }
		    else if(slotInd == 1)
		    {
			    jewelSlot = waistSlot2;
		    }
		    else
		    {
			    jewelSlot = waistSlot3;
		    }
	    }
	    else if(bodyPart == 4)
	    {
		    if(slotInd == 0)
		    {
			    jewelSlot = legSlot1;
		    }
		    else if(slotInd == 1)
		    {
			    jewelSlot = legSlot2;
		    }
		    else
		    {
			    jewelSlot = legSlot3;
		    }
	    }
	    else if(bodyPart == 5)  //weapon
	    {
		    if(slotInd == 0)
		    {
			    jewelSlot = weaponSlot1;
		    }
		    else if(slotInd == 1)
		    {
			    jewelSlot = weaponSlot2;
		    }
		    else
		    {
			    jewelSlot = weaponSlot3;
		    }
	    }
	    else //charm slots
	    {
		    if(slotInd == 0)
		    {
			    jewelSlot = charmSlot1;
		    }
		    else if(slotInd == 1)
		    {
			    jewelSlot = charmSlot2;
		    }
		    else
		    {
			    jewelSlot = charmSlot3;
		    }
	    }
	    return jewelSlot;

    }

    public void changeArmorMenu(int bodyPart,boolean lowRank, boolean blade,
	    boolean female, boolean active)
    {
	    JComboBox bodyMenu = getArmorMenuObj(bodyPart);

	    if(!active)
	    {
		    bodyMenu.setVisible(false);
		    return;
	    }

	    int[] ind = mhagData.getArmorList(lowRank, blade, female, bodyPart);
	    int num = ind.length;
	    String[] name = mhagData.getArmorListMenu(bodyPart, female, num, ind);

	    ArrayList<String> toolTips = new ArrayList<String>();

	    bodyMenu.removeAllItems();

	    //first null entry
	    bodyMenu.addItem(name[0]);
	    toolTips.add("---");
	    for(int i = 1; i < num; i++)
	    {
		    bodyMenu.addItem(name[i]);
		    Armor armor = mhagData.getArmor(bodyPart, ind[i]);
		    toolTips.add(armor.getToolTips());
	    }

	    rendererArmor[bodyPart].setTooltips(toolTips);
	    bodyMenu.setVisible(true);

    }

    public void changeJewelSlot(int bodyPart, int slotInd,
	    boolean lowRank, int nSlot, boolean active)
    {
	    int[] jewelIndOld = new int[3];
	    for (int i = 0; i < 3; i++)  //walkaround,,removeAllItems() kills some jewelInd ata
		    jewelIndOld[i] = jewelInd[bodyPart][i];

	    JComboBox jewelSlot = getJewelSlotObj(bodyPart, slotInd);

	    if(!active)
	    {
		    jewelSlot.setVisible(false);
		    return;
	    }

	    int[] ind = mhagData.getJewelList(lowRank, nSlot);
	    int num = ind.length;

	    jewelSlot.removeAllItems();
	    ArrayList<String> toolTips = new ArrayList<String>();

	    jewelSlot.addItem("---"); //1st null item
	    toolTips.add("---");
	    for(int i = 1; i < num; i++)
	    {
 		    Jewel jewel = mhagData.getJewel(ind[i]);
		    jewelSlot.addItem(jewel.getJewelNameSkill());
		    toolTips.add(jewel.getJewelToolTips());
	    }
	    renderer[bodyPart][slotInd].setTooltips(toolTips);
	    jewelSlot.setVisible(true);

	    // keep the jewel ID if previously active
	    for (int i = 0; i < 3; i++) //walkaround
		    jewelInd[bodyPart][i] = jewelIndOld[i];

	    int[] indOld = mhagData.getJewelList(lowRank, jewelMenuType[bodyPart][slotInd]);

	    int id = indOld[jewelInd[bodyPart][slotInd]];
	    if(id != -1 )
	    {
		    for (int i = 1; i < num; i++)
		    {
			    if(ind[i] == id)
			    {
				    jewelSlot.setSelectedIndex(i);
				    jewelInd[bodyPart][slotInd] = i;
				    break;
			    }
		    }
	    }

	    jewelMenuType[bodyPart][slotInd] = nSlot;
    }

    public void changeCharmSkill(int skillNo,String skillClass, boolean active)
    {

	    JComboBox skillSlot;
	    JLabel skillLabel;
	    int exception;
	    if(skillNo == 0)
	    {
		    skillSlot = charmSkill1;
		    skillLabel = skillPoint1;
		    exception = set.getCharmSkillID()[1];
	    }
	    else
	    {
		    skillSlot = charmSkill2;
		    skillLabel = skillPoint2;
		    exception = set.getCharmSkillID()[0];
	    }

	    if(!active)
	    {
		    skillSlot.setVisible(false);
		    skillLabel.setVisible(false);
		    return;
	    }

		int[] ind = mhagData.getSkillList(skillClass, exception);
		int num = ind.length;

		skillSlot.removeAllItems();
		//skillSlot.addItem("---"); //No 1st null item
		int selectedInd = 0;
		for(int i = 0; i < num; i++)
		{
			Skill skill = mhagData.getSkill(ind[i]);
			skillSlot.addItem(skill.getSkillName());
			if(skill.getSkillID() == set.getCharmSkillID()[skillNo])
			{
				skillSlot.setSelectedIndex(i);
				selectedInd = i;
			}
		}

	    skillSlot.setVisible(true);
	    skillLabel.setVisible(true);
	    set.setCharmSkillID(skillNo,ind[selectedInd]);

    }

    public void changeCharmMenu(boolean lowRank)
    {

		int[] ind = mhagData.getCharmList(lowRank);
		int num = ind.length;

		charmMenu.removeAllItems();
		charmMenu.addItem("---"); //1st null item
		for(int i = 1; i < num; i++)
		{
			Charm charm = mhagData.getCharm(ind[i]);
			charmMenu.addItem(charm.getCharmName());
		}

	   charmMenu.setVisible(true);

    }

    public void initSetup(boolean lowRank, boolean blade, boolean female)
    {
	    for(int i = 0; i < 5; i++)
		    changeArmorMenu(i, lowRank, blade, female, true);

	    for(int i = 0; i < 7; i++)
	    {
		    for(int j = 0; j < 3; j++) // number 1-3
		    {
			changeJewelSlot(i, j, lowRank, 0, false);
		    }
	    }

	    weaponMenu.setSelectedIndex(0);  //reset Weapon menu

	    changeCharmMenu(lowRank);

	    for(int i = 0; i < 2; i++)
		    changeCharmSkill(i, "D", false);

    }

    public void changeGender(boolean lowRank, boolean blade, boolean female)
    {
	    adjust = true;
	    for(int i = 0; i < 5; i++)
	    {
		    JComboBox bodyMenu = getArmorMenuObj(i);

		    int entryOld = bodyMenu.getSelectedIndex();
		    int[] indOld = mhagData.getArmorList(lowRank, blade, !female, i);

		    int[] ind = mhagData.getArmorList(lowRank, blade, female, i);
		    int num = ind.length;
		    String[] name = mhagData.getArmorListMenu(i, female, num, ind);

		    ArrayList<String> toolTips = new ArrayList<String>();

		    bodyMenu.removeAllItems();
		    bodyMenu.addItem(name[0]);
		    toolTips.add("---");
		    for(int j = 1; j < num; j++)
		    {
			    bodyMenu.addItem(name[j]);
			    if(ind[j] == indOld[entryOld])
			    {
				    bodyMenu.setSelectedIndex(j);
			    }
			    Armor armor = mhagData.getArmor(i, ind[j]);
			    toolTips.add(armor.getToolTips());
		    }
		    rendererArmor[i].setTooltips(toolTips);
	    }
	    adjust = false;

    }

    public void calSetGUI()
    {
	   //boolean pass = set.checkSet(mhag, mhagData);  //check set
	   //if(!pass)
	   //{
	   //	   System.out.println("Error! Please Check!");
	   //      MhagUtil.logLine(mhag, "Error! Please Check!");
	   //}
	    String name = jTextSetName.getText();
	    set.setSetName(name);

	   set.calcSet(mhag, mhagData);   //calculate set

	   stream.reset();
  	   set.save(mhag, mhagData, stream);  // save results
	   stream.rewind();
    }

    //check preference file
    public void checkPref()
    {

	try {
		Scanner filein = new Scanner(new File(fileNamePref));

		int count = 0;
		while (filein.hasNext() && (count < 2))
		{
			if(count == 0)
			{
				fileNameData = filein.nextLine();
				jTextData.setText(fileNameData);
			}
			else
			{
				fileNameCodeBook = filein.nextLine();
				codeBookName.setText(fileNameCodeBook);
			}
			count++;
		}
		filein.close();


	} catch (FileNotFoundException ex) {
	}

    }

    // save preference file
    public void savePref() throws FileNotFoundException
    {
	    PrintStream fileout = new PrintStream(new File(fileNamePref));
	    fileout.println(fileNameData);
	    fileout.println(fileNameCodeBook);
	    fileout.close();
    }

    // read help from USAGE.txt
    public void readHelp()
    {
	try {
		Scanner filein = new Scanner(new File("USAGE.txt"));

		Arrays.fill(helpData, "");
		int num = 0;

		    listModelHelp.clear();
		    while(filein.hasNext())
		    {
			    String line = filein.nextLine();
			    int pos = line.indexOf(":");
			    if(pos == -1)continue;

			    listModelHelp.addElement(line.substring(0, pos));
			    helpData[num] = line.substring(pos+1);
			    num++;
		    }

		    helpList.setModel(listModelHelp);


	} catch (FileNotFoundException ex) {
		return;
	}

    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {

                MhagGui mhagGui = new MhagGui();

		try {
			mhagGui.initMhag();  // initialize mhag
		} catch (FileNotFoundException ex) {
			Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
		}

		mhagGui.checkPref();
		mhagGui.readHelp();

		mhagGui.stream = new TextAreaPrintStream(mhagGui.jTextPreview, System.out);
	        mhagGui.streamView = new TextAreaPrintStream(mhagGui.jTextPreview2, System.out);

		mhagGui.setVisible(true);

		mhagGui.initSetup(false, true, false); // by default

		//mhagGui.jTextUsage.setCaretPosition(0);
		mhagGui.jTabbedPane1.setEnabledAt(2, false);

				try {
					UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
				} catch (ClassNotFoundException ex) {
					Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
				} catch (InstantiationException ex) {
					Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
				} catch (IllegalAccessException ex) {
					Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
				} catch (UnsupportedLookAndFeelException ex) {
					Logger.getLogger(MhagGui.class.getName()).log(Level.SEVERE, null, ex);
				}
            }
        });
    }

    	// GUI MHAG variables
    	private Mhag mhag = new Mhag();
    	private Set set = new Set();
    	private MhagData mhagData = new MhagData();
	private TextAreaPrintStream stream, streamView;
	private int[][] jewelInd = new int[7][3]; //jewel index in each jewel button list
	private int[][] jewelMenuType = new int[7][3]; //menu type in each jewel button position
	private boolean adjust = false; // adjust menu, don't perform calculation
	int saveOpt =0;  //save option for GUI

	private ComboboxToolTipRenderer[][] renderer = new ComboboxToolTipRenderer[7][3];
	//renderer for slot menu tooltips
	private ComboboxToolTipRenderer[] rendererArmor = new ComboboxToolTipRenderer[5];

	private boolean codeBookInUse = false;
	private DefaultListModel listModel =  new DefaultListModel(); //viewer code list

	private String[] deletedCodes = new String[5]; //store deleted codes;

	// save code book
	private boolean codeBookChanged = false;   //save code book dialog
	SaveAndExit dialogSave = new SaveAndExit(new javax.swing.JFrame(), true);

	// save code book/outputs data file names
	private final String fileNamePref = "pref";
	private String fileNameData = "MyData";
	private String fileNameCodeBook = "MyData";

	//help list
	private DefaultListModel listModelHelp =  new DefaultListModel(); //viewer help list
	private String[] helpData = new String[100];  // help data, max 100 entries

        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JButton Output;
        private javax.swing.JPanel about;
        private javax.swing.JComboBox armSlot1;
        private javax.swing.JComboBox armSlot2;
        private javax.swing.JComboBox armSlot3;
        private javax.swing.JLabel armsLabel;
        private javax.swing.JComboBox armsMenu;
        private javax.swing.JRadioButton blade;
        private javax.swing.ButtonGroup buttonGroup1;
        private javax.swing.JPanel calculator;
        private javax.swing.JLabel charmLabel;
        private javax.swing.JComboBox charmMenu;
        private javax.swing.JComboBox charmSkill1;
        private javax.swing.JComboBox charmSkill2;
        private javax.swing.JLabel charmSkillLabel;
        private javax.swing.JComboBox charmSlot1;
        private javax.swing.JComboBox charmSlot2;
        private javax.swing.JComboBox charmSlot3;
        private javax.swing.JLabel chestLabel;
        private javax.swing.JComboBox chestMenu;
        private javax.swing.JComboBox chestSlot1;
        private javax.swing.JComboBox chestSlot2;
        private javax.swing.JComboBox chestSlot3;
        private javax.swing.JRadioButton code;
        private javax.swing.JPanel codeBook;
        private javax.swing.JButton codeBookLoad;
        private javax.swing.JTextField codeBookName;
        private javax.swing.JButton codeBookSave;
        private javax.swing.JList codeList;
        private javax.swing.JPanel convert;
        private javax.swing.JRadioButton convertHTML;
        private javax.swing.JRadioButton convertTEXT;
        private javax.swing.JButton deleteInteract;
        private javax.swing.JRadioButton female;
        private javax.swing.JPanel generator;
        private javax.swing.JButton getSetInteract;
        private javax.swing.JRadioButton gunner;
        private javax.swing.JLabel headLabel;
        private javax.swing.JComboBox headMenu;
        private javax.swing.JComboBox headSlot1;
        private javax.swing.JComboBox headSlot2;
        private javax.swing.JComboBox headSlot3;
        private javax.swing.JList helpList;
        private javax.swing.JTextArea helpText;
        private javax.swing.JRadioButton highRank;
        private javax.swing.JRadioButton html;
        private javax.swing.JPanel hunterType;
        private javax.swing.ButtonGroup hunterTypeGroup;
        private javax.swing.JEditorPane jEditorAbout;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JScrollPane jScrollAbout;
        private javax.swing.JScrollPane jScrollHelpList;
        private javax.swing.JScrollPane jScrollHelpText;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPreview;
        private javax.swing.JScrollPane jScrollPreview2;
        private javax.swing.JTabbedPane jTabbedPane1;
        private javax.swing.JTextField jTextData;
        private javax.swing.JTextArea jTextPreview;
        private javax.swing.JTextArea jTextPreview2;
        private javax.swing.JTextField jTextSetName;
        private javax.swing.JComboBox legSlot1;
        private javax.swing.JComboBox legSlot2;
        private javax.swing.JComboBox legSlot3;
        private javax.swing.JLabel legsLabel;
        private javax.swing.JComboBox legsMenu;
        private javax.swing.JButton loadSetInteract;
        private javax.swing.JRadioButton lowRank;
        private javax.swing.JRadioButton male;
        private javax.swing.JPanel output;
        private javax.swing.ButtonGroup outputGroup;
        private javax.swing.JPanel rank;
        private javax.swing.ButtonGroup rankGroup;
        private javax.swing.JButton saveOutput;
        private javax.swing.JPanel setNamePanel;
        private javax.swing.JPanel setup;
        private javax.swing.JPanel sex;
        private javax.swing.ButtonGroup sexGroup;
        private javax.swing.JLabel skillPoint1;
        private javax.swing.JLabel skillPoint2;
        private javax.swing.JRadioButton text;
        private javax.swing.JButton undoInteract;
        private javax.swing.JPanel viewer;
        private javax.swing.JLabel waistLabel;
        private javax.swing.JComboBox waistMenu;
        private javax.swing.JComboBox waistSlot1;
        private javax.swing.JComboBox waistSlot2;
        private javax.swing.JComboBox waistSlot3;
        private javax.swing.JLabel weaponLabel;
        private javax.swing.JComboBox weaponMenu;
        private javax.swing.JComboBox weaponSlot1;
        private javax.swing.JComboBox weaponSlot2;
        private javax.swing.JComboBox weaponSlot3;
        // End of variables declaration//GEN-END:variables

}
